package controller;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.image.ImageView;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import sample.*;
import sample.Admin.Admin;
import sample.student.Student;
import sample.teacher.Teacher;
import sql.LoginJDBC;

public class MainController {
//    @FXML
//    private Button mbutton1;
//    @FXML
//    private  Button mbutton2;
    @FXML
    private TextField musername;
    @FXML
    private PasswordField mpassword;
    @FXML
    private ImageView loginpic;

    @FXML
    public void initialize() {
        Circle circle = new Circle(42);
        loginpic.setClip(circle);
        circle.setCenterX(loginpic.getX()+loginpic.getFitWidth()/2);
        circle.setCenterY(loginpic.getY()+loginpic.getFitHeight()/2);
//        loginpic.setClip(clip);
//
        // snapshot the rounded image.
//        SnapshotParameters parameters = new SnapshotParameters();
//        parameters.setFill(Color.TRANSPARENT);
//        WritableImage image = loginpic.snapshot(parameters, null);
//
//        // remove the rounding clip so that our effect can show through.
//        loginpic.setClip(null);
//
//        // apply a shadow effect.
//        loginpic.setEffect(new DropShadow(20, Color.BLACK));
//
//        // store the rounded image in the imageView.
//        loginpic.setImage(image);
    }

    public boolean click()throws Exception{
//        this.initialize();
        System.out.println("okk");
        LoginJDBC  loginJDBC = new LoginJDBC();
        loginJDBC.initialize();
        String username = musername.getText();
        String password = mpassword.getText();
        Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.setTitle("Information Dialog");
        alert.setHeaderText("提示:");
        if(username.isEmpty()||password.isEmpty()){
            alert.setContentText("请检查输入！！！");
            alert.showAndWait();
        }
        else{
            switch (LoginJDBC.login(username, password)){
                case 0:alert.setContentText("无此用户名");
                    alert.showAndWait(); return false;
                case 1: new Admin(username,password).start(new Stage()); return true; //
                case 2: new Student(username,password).start(new Stage()); return true;
                case 3: new Teacher(username,password).start(new Stage());  return true;
                case -1:
                    alert.setContentText("请检查输入 密码不正确");
                    alert.showAndWait();
            }
        }
        return false;
        }

    public void click2()throws Exception{
        Register register = new Register();
        Stage stage = new Stage();
        register.start(stage);

    }


}
